package com.reportes;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRResultSetDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

import com.Reporte;

import exceptions.InvalidArgumentException;

public class Estado extends Reporte {

	@Override
	public void VerificarParametros(HttpServletRequest request)
	throws InvalidArgumentException {

		setParametrosJasper("parametro",request.getParameter("parametroConsulta"));
		}

		@Override
		public Object clone() throws CloneNotSupportedException {
			Estado reporte = new Estado();
			copyAttributesTo(reporte);
			return reporte;
		}

	@Override
	protected JRDataSource executeQuery(Connection connection)
	throws SQLException {
	StringBuffer sql =
	new StringBuffer("select estado.nombre, estado.codigo, estado.capital")
			.append(" FROM" )
			.append(" Estado")
			.append(" ORDER by estado.id");
		Statement statement = connection.createStatement();
		ResultSet rs = statement.executeQuery(sql.toString());
		return new JRResultSetDataSource(rs);
	}

}
